package com.jishuo.nontax.web.checkbill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.BankBalanceVO;
import com.jishuo.nontax.bfc.service.BankBalanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 余额
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/bankbalance", name = "余额")
@UserAuthority(menu = {"bill/bankbalance/bankbalance","bill/basedata/basedata"})
public class BankBalanceController {
    @Resource
    private BankBalanceService bankBalanceService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"bankbalance"}, name = "缴款书首页")
    public String index(@PathVariable(required = false) String page) {
        return prefix + "bankbalance";
    }

 /**
  * @author hlp
  * @date 2023/3/13 12:03
  * @Description: 余额列表分页
  */
    @ResponseBody
    @RequestMapping(value = "findBankBalancePage", name = "余额列表分页")
    public GridResult<BankBalanceVO> findBankBalancePage(BankBalanceVO bankBalanceVO, Pagination pagination) {
        return new GridResult<>(bankBalanceService.findBankBalancePage(bankBalanceVO,pagination));
    }


    /**
     * @author hlp
     * @date 2023/3/13 14:43
     * @Description: 添加余额
     */
    @ResponseBody
    @RequestMapping(value = "insertBankBalance", name = "添加余额")
    public BaseResult insertBankBalance(BankBalanceVO bankBalanceVO) {
        return bankBalanceService.insertBankBalance(bankBalanceVO);
    }
    /**
     * @author hlp
     * @date 2023/3/13 14:43
     * @Description: 修改余额
     */
    @ResponseBody
    @RequestMapping(value = "updateBankBalance", name = "修改余额")
    public BaseResult updateBankBalance(BankBalanceVO bankBalanceVO) {
        return bankBalanceService.updateBankBalance(bankBalanceVO);
    }

    /**
     * @author hlp
     * @date 2023/3/13 16:14
     * @Description: 删除余额
     */
    @ResponseBody
    @RequestMapping(value = "deleteBankBalance", name = "删除余额")
    public BaseResult deleteBankBalance(int bankid, String accountdate) {
        return bankBalanceService.deleteBankBalance(bankid, accountdate);
    }

    /**
     * @author hlp
     * @date 2023/3/14 10:03
     * @Description: 余额发送财政
     */
    @ResponseBody
    @RequestMapping(value = "sendBankBalance", name = "余额发送财政")
    public BaseResult sendBankBalance(int bankid, String accountdate ,String usercode, String userpwd, HttpSession session) throws Exception {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return bankBalanceService.sendBankBalance(bankid,accountdate, true);
    }

    @ResponseBody
    @RequestMapping(value = "findBankBalanceExport", name = "余额列表导出")
    public void findBankBalanceExport(BankBalanceVO bankBalanceVO, HttpServletResponse response) throws IOException {
        bankBalanceService.findBankBalanceExport(bankBalanceVO,response);
    }

}
